e21498e2e935b47965e03516d77e9eda934279cd,src/main/java/at/favre/tools/uberadb/actions/BugReport.java,BugReport,create,#AdbLocationFinder.LocationResult#Arg#List#AdbDevice#List#,16
Before Change
CmdUtil.Result screecapCmd = Commons.runAdbCommand(new String[]{"-s", device.serial, "shell", "screencap", tempFileScreenshot}, adbLocation);
CmdUtil.Result pullscreenCmd = Commons.runAdbCommand(new String[]{"-s", device.serial, "pull", tempFileScreenshot, localTempFileScreenshot.getAbsolutePath()}, adbLocation);
Commons.log("\tcreate logcat file and pull from device", arguments);
CmdUtil.Result logcat = Commons.runAdbCommand(new String[]{"-s", device.serial, "logcat", "-d", "-f", tempFileLogcat}, adbLocation);
CmdUtil.Result pullLogcatCmd = Commons.runAdbCommand(new String[]{"-s", device.serial, "pull", tempFileLogcat, localTempFileLogcat.getAbsolutePath()}, adbLocation);
Commons.log(String.format(Locale.US, "\t%.2fkB screenshot, %.2fkB logcat",
(double) localTempFileScreenshot.length() / 1024.0, (double) localTempFileLogcat.length() / 1024.0), arguments);
CmdUtil.Result removeTempFiles1Cmd = Commons.runAdbCommand(new String[]{"-s", device.serial, "shell", "rm", "-f", tempFileScreenshot}, adbLocation);
CmdUtil.Result removeTempFiles2Cmd = Commons.runAdbCommand(new String[]{"-s", device.serial, "shell", "rm", "-f", tempFileLogcat}, adbLocation);
executedCommands.add(wakeupScreenCmd);
executedCommands.add(screecapCmd);
executedCommands.add(pullscreenCmd);
executedCommands.add(logcat);
executedCommands.add(pullLogcatCmd);
executedCommands.add(removeTempFiles1Cmd);
executedCommands.add(removeTempFiles2Cmd);
MiscUtil.zip(zipFile, Arrays.asList(localTempFileScreenshot, localTempFileLogcat));
localTempFileScreenshot.delete();
After Change
import java.util.*;
public class BugReport {
public static void create(AdbLocationFinder.LocationResult adbLocation, Arg arguments, List<CmdUtil.Result> executedCommands, AdbDevice device, List<String> allPackages) throws Exception {
Commons.logLoud("create bug report:");
String dateTimeString = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss-SSS").format(new Date());
File outFolder;
if (arguments.mainArgument != null && !arguments.mainArgument.isEmpty()) {
outFolder = new File(arguments.mainArgument);
if (!outFolder.exists() && !outFolder.mkdirs()) {
throw new IllegalStateException("could not create directory " + arguments.mainArgument);
}
} else {
outFolder = new File(AdbTool.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
}
if (arguments.reportFilterIntent != null && arguments.reportFilterIntent.length >= 2) {
Set<String> filteredPackages = new PackageMatcher(allPackages).findMatches(
PackageMatcher.parseFiltersArg(arguments.reportFilterIntent[0]));
for (String filteredPackage : filteredPackages) {
String[] copy = Arrays.copyOfRange(arguments.reportFilterIntent, 1, arguments.reportFilterIntent.length);
for (int i = 0; i < copy.length; i++) {
copy[i] = copy[i].replace("${package}", filteredPackage);
}
CmdUtil.Result uninstallCmdResult = Commons.runAdbCommand(CmdUtil.concat(new String[]{"-s", device.serial, "shell", "am",}, copy), adbLocation);
executedCommands.add(uninstallCmdResult);
String intentStatus = "\texecute command for " + filteredPackage + " - adb shell am " + Arrays.toString(copy);
Commons.log(intentStatus, arguments);
Thread.sleep(100);
}
}
String tempFileScreenshot = "/sdcard/bugreport_tempfile_screenshot.png";
String tempFileLogcat = "/sdcard/bugreport_tempfile_logcat";
File localTempFileScreenshot = new File(outFolder.getAbsolutePath(), "screen-" + device.model + "-" + dateTimeString + ".png");
File localTempFileLogcat = new File(outFolder.getAbsolutePath(), "logcat-" + device.model + "-" + dateTimeString + ".txt");
File zipFile = new File(outFolder, "bugreport-" + device.model + "-" + dateTimeString + ".zip");
Commons.log("\twake up screen and take screenshot", arguments);
executedCommands.add(Commons.runAdbCommand(new String[]{"-s", device.serial, "shell", "input", "keyevent", "KEYCODE_WAKEUP"}, adbLocation));
executedCommands.add(Commons.runAdbCommand(new String[]{"-s", device.serial, "shell", "screencap", tempFileScreenshot}, adbLocation));
executedCommands.add(Commons.runAdbCommand(new String[]{"-s", device.serial, "pull", tempFileScreenshot, localTempFileScreenshot.getAbsolutePath()}, adbLocation));
Commons.log("\tcreate logcat file and pull from device", arguments);
executedCommands.add(Commons.runAdbCommand(new String[]{"-s", device.serial, "logcat", "-d", "-f", tempFileLogcat}, adbLocation));
executedCommands.add(Commons.runAdbCommand(new String[]{"-s", device.serial, "pull", tempFileLogcat, localTempFileLogcat.getAbsolutePath()}, adbLocation));
Commons.log(String.format(Locale.US, "\t%.2fkB screenshot, %.2fkB logcat",
(double) localTempFileScreenshot.length() / 1024.0, (double) localTempFileLogcat.length() / 1024.0), arguments);
executedCommands.add(Commons.runAdbCommand(new String[]{"-s", device.serial, "shell", "rm", "-f", tempFileScreenshot}, adbLocation));
executedCommands.add(Commons.runAdbCommand(new String[]{"-s", device.serial, "shell", "rm", "-f", tempFileLogcat}, adbLocation));
MiscUtil.zip(zipFile, Arrays.asList(localTempFileScreenshot, localTempFileLogcat));
localTempFileScreenshot.delete();